/**   
 * @Title: MyInfoCommunicater.java 
 * @Package： com.esun.rabbit2.communicaters.myinfo 
 * @Description: 我的信息
 * @Author Miko baoz@500wan.com   
 * @Date 2011-7-4 下午03:13:33  
 * Copyright (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.communicaters.myinfo;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.client.ClientProtocolException;
import org.xml.sax.SAXException;

import com.esun.config.BussinessCode;
import com.esun.config.Key;
import com.esun.model.UserInfo;
import com.esun.model.UserInfoDetailInfo;
import com.esun.network.ServerCommunicater;

/**
 * @ClassName: MyInfoCommunicater
 * @Description: 我的信息通讯类
 * @author Miko baoz@500wan.com
 * @date 2011-7-4 下午03:13:33
 * 
 */
public class MyInfoCommunicater extends ServerCommunicater {

	public boolean getMyInfo() throws ClientProtocolException, IOException, ParserConfigurationException, SAXException {
		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();

		list.add(mapItem(BussinessCode.PASER_MID, BussinessCode.MID_GET_USERINFO));
		list.add(mapItem(BussinessCode.PASER_CK, UserInfo.getUserInfo().getUserSession()));

		super.getServerResponse(list, true);

		if (super.getState() == 100) {
			updateUserInfo();
			return true;
		} else {
			return false;
		}
	}

	public void updateUserInfo() {

		UserInfoDetailInfo.getUserInfoDetailInfo().setUserName(super.getResult().get(Key.KEY_F_USERNAME));
		UserInfoDetailInfo.getUserInfoDetailInfo().setSex(super.getResult().get(Key.KEY_UI_SEX));
		UserInfoDetailInfo.getUserInfoDetailInfo().setTelPhone(super.getResult().get(Key.KEY_UI_PHONE));
		UserInfoDetailInfo.getUserInfoDetailInfo().setEmail(super.getResult().get(Key.KEY_UI_EMAIL));
		UserInfoDetailInfo.getUserInfoDetailInfo().setAddress(super.getResult().get(Key.KEY_UI_ADDRESS));
		UserInfoDetailInfo.getUserInfoDetailInfo().setPostCode(super.getResult().get(Key.KEY_UI_ZIPCODE));
		UserInfoDetailInfo.getUserInfoDetailInfo().setBalance(super.getResult().get(Key.KEY_MONEY));
		UserInfoDetailInfo.getUserInfoDetailInfo().setRealName(super.getResult().get(Key.KEY_UI_TRUENAME));
		UserInfoDetailInfo.getUserInfoDetailInfo().setIDNum(super.getResult().get(Key.KEY_UI_IDCODE));
		UserInfoDetailInfo.getUserInfoDetailInfo().setMobileNum(super.getResult().get(Key.KEY_UI_MOBILE));
		UserInfoDetailInfo.getUserInfoDetailInfo().setBankNum(super.getResult().get(Key.KEY_BANKCARDNO));
		UserInfoDetailInfo.getUserInfoDetailInfo().setUserIconName(super.getResult().get(Key.KEY_F_USERICON));

		UserInfo.getUserInfo().seteMail(super.getResult().get(Key.KEY_UI_EMAIL));
		UserInfo.getUserInfo().setMobile(super.getResult().get(Key.KEY_UI_MOBILE));
		UserInfo.getUserInfo().setRealName(super.getResult().get(Key.KEY_UI_TRUENAME));
		UserInfo.getUserInfo().setUserBalance(super.getResult().get(Key.KEY_MONEY));
		UserInfo.getUserInfo().setUserName(super.getResult().get(Key.KEY_F_USERNAME));

	}

	private HashMap<String, String> mapItem(String name, String value) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put(name, value);
		return map;
	}

}
